<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Order extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('order', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('num')->comment('订单号');
            $table->unsignedBigInteger('customer_id')->comment('客户ID');
            $table->decimal('total_money',10,2)->comment('订单总金额');
            $table->decimal('payed_money',10,2)->default(0)->comment('收款金额');
            $table->decimal('cost_money',10,2)->default(0)->comment('支出金额');
            $table->date('stime')->nullable()->comment('下单日期');
            $table->date('etime')->nullable()->comment('交单日期');
            $table->text('remark')->nullable()->comment('备注');
            $table->string('product_ids')->nullable()->comment('业务产品ID，多个用,隔开');
            $table->text('multiple_file')->nullable()->comment('附件，多个用,隔开');
            $table->tinyInteger('pay_type')->nullable()->comment('付款方式：1全款，2分期付款');
            $table->decimal('first_money',10,2)->nullable()->comment('前期款');
            $table->decimal('mid_money',10,2)->nullable()->comment('中期款');
            $table->decimal('last_money',10,2)->nullable()->comment('尾款');

            $table->unsignedBigInteger('owner_user_id')->default(0)->comment('订单所属人ID');
            $table->string('owner_user_nickname')->nullable()->comment('订单所属人名称');
            $table->unsignedBigInteger('owner_department_id')->default(0)->comment('订单所属人部门ID');

            $table->tinyInteger('check_status')->default(1)->comment('审核状态：2审核不通过，3审核通过，默认1');
            $table->text('check_result')->nullable()->comment('审核结果内容');
            $table->dateTime('check_time')->nullable()->comment('审核时间');
            $table->unsignedBigInteger('check_user_id')->default(0)->comment('审核用户ID');
            $table->string('check_user_nickname')->nullable()->comment('审核用户名称');

            $table->dateTime('send_time')->nullable()->comment('分单时间');
            $table->string('send_user_nickname')->nullable()->comment('分单人名称');
            $table->unsignedBigInteger('send_user_id')->default(0)->comment('分单人ID');
            $table->unsignedBigInteger('send_department_id')->default(0)->comment('分单人部门ID');
            $table->dateTime('accept_time')->nullable()->comment('接单时间');
            $table->string('accept_user_nickname')->nullable()->comment('接单人名称');
            $table->unsignedBigInteger('accept_user_id')->default(0)->comment('接单人ID');
            $table->unsignedBigInteger('accept_department_id')->default(0)->comment('接单人部门ID');

            $table->unsignedBigInteger('node_id')->default(0)->comment('节点ID');
            $table->string('node_name')->nullable()->comment('节点名称');
            $table->tinyInteger('status')->default(0)->comment('状态：0进行中，1退单,2完结');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order');
    }
}
